package edu.gatech.cs2340.thecyclonesquad;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import edu.gatech.cs2340.thecyclonesquad.database.Database;
import edu.gatech.cs2340.thecyclonesquad.models.InMemoryModel;
import android.os.Build;
import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;

public class FilterLostDateActivity extends Activity {
	
	Date date = null;
	@SuppressLint("SimpleDateFormat")
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	private ArrayAdapter<String> mListData9;


	/**
	 * Initializes our activity.
	 */
	@SuppressLint("NewApi")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_filter_lost_date);
		// Make sure we're running on Honeycomb or higher to use ActionBar APIs
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            // Show the Up button in the action bar.
            getActionBar().setDisplayHomeAsUpEnabled(true);
        }
	}

	/**
	 * Initialize the contents of the Activity's standard options menu.
	 */
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_filter_lost_date, menu);
		return true;
	}
	
	/**
	 * Filter lost items by date.
	 * @param view is the basic building block for UI components
	 */
	public void dateFilter(View view) {
		EditText editText = (EditText) findViewById(R.id.date2);
		String dateString = editText.getText().toString();
		try {
			date = sdf.parse(dateString);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
        //get handle of list
        ListView lvList9 = (ListView)findViewById(R.id.listView9);
        //creates an adapter to hold values for the list
        //Array adapter constructor has a List Item layout and the context
        //String items[] = lostitems.filterByDate("Lost", date);
        Database entry = new Database(this);
    	entry.open();
    	String items[] = entry.getItems("Lost", date);
    	entry.close();
        mListData9 = new ArrayAdapter<String>(FilterLostDateActivity.this, android.R.layout.simple_list_item_1, items);
        //Set adapter to the list
        lvList9.setAdapter(mListData9);
	}

	/**
	 * logOut method logs the user out and goes back to login page.
	 * @param view is the basic building block for UI components
	 */
	public void logOut(View view) {
		Intent intent = new Intent(this, SignInActivity.class);
		startActivity(intent);			
	}


}
